package com.rw.bootdemo.exception;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@ControllerAdvice
public class ExceptionController {


    @ExceptionHandler(NullPointerException.class)
    @ResponseBody
    public Map<String,String> getException2(){
        Map<String, String> result = new HashMap<>();
        result.put("msg","空指针异常");
        result.put("code","200");
        return  result;

    }


    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public Map<String,String> getException(){
        Map<String, String> result = new HashMap<>();
        result.put("msg","ExceptionController报错了");
        return  result;

    }
}
